﻿using Blurift.WPFGLControl;
using Crevice2D.Core.Batches;
using Crevice2D.Core.Infrastructure;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Patyk.Core.Infrastructure;

namespace Crevice2D.WPFEditorHost
{
    public enum Mode
    {
        EditNodes
    }

    public class Editor : BaseEditor, IBaseEditor
    {
        private Mode _activeMode;
        public void SetMode(Mode mode) { _activeMode = mode; }
        public Mode GetMode(){ return _activeMode; }

        //Mouse Buttons HOLD flags
        protected bool mouseLHold = false;
        protected bool mouseRHold = false;
        protected bool mouseMHold = false;

        //Mouse Buttons positions
        protected static int _mouseX;
        protected static int _mouseY;
        protected static int _mousedXMove;
        protected static int _mousedYMove;
        protected static MouseState _mouseState;

        public static MouseState MouseState { get { return _mouseState; } }
        public static Point MousePos { get { return new Point(_mouseX, _mouseY); } }
        public static Point MouseMove { get { return new Point(_mousedXMove, _mousedYMove); } }

        public Editor()
        {
            _activeMode = Mode.EditNodes;
        }

        public virtual void Initialize()
        {

        }

        public virtual void LoadContent()
        {

        }

        public virtual void UnloadContent()
        {

        }

#region Mouse Handlers

        public virtual void MouseLDown(HwndMouseEventArgs e)
        {
            mouseLHold = true;
        }
        public virtual void MouseLUp(HwndMouseEventArgs e)
        {
            mouseLHold = false;
        }
        public virtual void MouseRDown(HwndMouseEventArgs e)
        {
            mouseRHold = true;
        }
        public virtual void MouseRUp(HwndMouseEventArgs e)
        {
            mouseRHold = true;
        }
        public virtual void MouseMDown(HwndMouseEventArgs e)
        {
            mouseMHold = true;
        }
        public virtual void MouseMUp(HwndMouseEventArgs e)
        {
            mouseMHold = true;
        }

        public virtual void UpdateMouse(HwndMouseEventArgs e)
        {
            _mouseX = (int)e.Position.X;
            _mouseY = (int)e.Position.Y;

            _mousedXMove = (int)e.Position.X - (int)e.PreviousPosition.X;
            _mousedYMove = (int)e.Position.Y - (int)e.PreviousPosition.Y;
        }

#endregion

        public virtual void Draw()
        {
            DrawHUD();
        }

        private void DrawHUD()
        {

        }
    }
}
